package bookExercise;

import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

public class A14Reducing {
    public static void main(String[] args) {
        List<A14Emplyee> list = A14Emplyee.getEmpList();
        long count = list.stream().count();
        System.out.println("公司总人数："+count);

        Optional<A14Emplyee> maxAge =list.stream().
                collect(Collectors.maxBy(Comparator.comparingInt(A14Emplyee::getAge)));
        System.out.println("年龄最大的是："+maxAge.get());

        Optional<A14Emplyee> minAge =list.stream().
                collect(Collectors.minBy(Comparator.comparingInt(A14Emplyee::getAge)));
        System.out.println("年龄最小的是："+minAge.get());

        Double collect = list.stream().collect(Collectors.summingDouble(A14Emplyee::getSalary));
        System.out.println("公司总工资："+collect);

        list.stream().collect(Collectors.averagingDouble(A14Emplyee::getSalary));
        System.out.println("公司平均工资："+collect/list.size());

        List<String> collect1 = list.stream().map(A14Emplyee::getName).collect(Collectors.toList());
        System.out.println("公司所有员工姓名："+collect1);

    }
}
